<% include header.ejs %>

<body class="home blog" ondragstart="return false">
	<section class="hidden-xs">
		<ul class="cb-slideshow">
			<li>
				<span>苟利</span>
			</li>
			<li>
				<span>国家</span>
			</li>
			<li>
				<span>生死以</span>
			</li>
			<li>
				<span>岂能</span>
			</li>
			<li>
				<span>祸福</span>
			</li>
			<li>
				<span>趋避之</span>
			</li>
		</ul>
	</section>
	<% include rkey.ejs %>
	<% include nav.ejs %>
</body>
<div id="zan-bodyer">
	<div class="container">
		<div class="row">
			<div id="mainstay" class="col-md-8">
				<!-- 公告 -->
				<div class="well mybody2">
					<button type="button" class="close" data-dismiss="alert">&times;</button>

					<input type="text" class="form-control" id="title">
					<br>
					<br>

					<div class="well mybody2">
						<div id="editor2">

						</div>
					</div>

					<input type="hidden" id="fmpath" class="form-control">

					<div class="well mybody2" id="tx_img">
						点击此处上传封面
						<img src="" width="200px" height="200px">
					</div>

					<button class="btn btn-danger btn-small" name="submit" id="postcont">发布</button>

				</div>

				<!-- 分页结束 -->
			</div>
			
		</div>
	</div>
</div>
<% include chats.ejs%>
<% include footer.ejs%>




<script>
	
	var editor3 = new E('#editor2')
	editor3.customConfig.uploadImgShowBase64 = true // 使用 base64 保存图片
	editor3.create()
	
	 
	kefu = true;
	
	
	
	editor3.txt.html(`<%-editcont %>`)
	$('#title').val('<%=edittit %>')
	$("#tx_img img").attr("src",'<%=fmpath %>')
	jQuery('#fmpath').val('<%=fmpath %>')
	 
	 
	jQuery('#tx_img').click(function() {

		let that = this;
		uploadAction({
			url: '/blog/sendfm',
			success: function(result) {
				console.log(result)
				if(
					result
				) {

					jQuery('#tx_img img').attr("src", result.path)
					jQuery('#fmpath').val(result.path)
					//   that.$store.commit("updateavatar", result.data.pictureUrl);
				}
			},

		});
	})

	jQuery('#postcont').click(function() {

		jQuery.post("/blog/post", {
			"id":sid.bid || '',
			"title": jQuery('#title').val(),
			"content": editor3.txt.html(),
			"fmpath": jQuery('#fmpath').val(),
		}, function(res) {
			if(res == "1") {
				
				window.location = "/list";
			} else if(res == "-1") {
				//用户名不存在

				consoel.log("用户名不存在！");
			} else if(res == "-2") {
				//密码错误
				console.log("密码错误");
			}
		})
	})

	function onfilechange(e) {
		var files = e.target.files || e.dataTransfer.files;
		if(!files.length) return;
		//去上传
		let file = e.target.files[0];
		let $img = document.getElementById("tx_img");
		var windowURL = window.URL || window.webkitURL;
		var dataURL = windowURL.createObjectURL(files[0]); //前端图片实时预览
		$img.src = dataURL;
	}
	
	function GetRequest() {
					var url = location.search; //获取url中"?"符后的字串   
					var theRequest = new Object();   
					if (url.indexOf("?") != -1) {   
							var str = url.substr(1);   
							strs = str.split("&");   
							for(var i = 0; i < strs.length; i ++) {   
								theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
							}   
					}   
					
					return theRequest;   
				}   
					var sid=GetRequest()
					
</script>